package com.ssm.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.AccountEntityMapper;
import com.ssm.dao.StudentEntityMapper;
import com.ssm.entity.JobEntity;
import com.ssm.entity.StudentEntity;
import com.ssm.service.AccountService;
import com.ssm.service.StudentService;

import myUtils.Utils;

@Service("StudentServiceImpl")
@Transactional
public class StudentServiceImpl implements StudentService {
	
    @Autowired
    private StudentEntityMapper mapper; 
    
	@Override
	public void save(StudentEntity stu) {
		System.out.println(stu.getStuId());
		int result = mapper.insert(stu);
	}

	@Override
	public boolean update(StudentEntity stu) {
		int result = mapper.updateByPrimaryKey(stu);
		System.out.println("update-result"+ result);
		return true;
	}

	@Override
	public boolean delete(String id) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public StudentEntity findById(String id) {
		StudentEntity stu = mapper.selectByPrimaryKey(id);
		return stu;
	}
	
	@Override
	public StudentEntity findByAccountId(String accountId) {
		StudentEntity stu = mapper.selectByAccountId(accountId);
		return stu;
	}

	@Override
	public List<StudentEntity> findWithPage(Integer page, Integer pageNum) {
		if (page == null || pageNum == null) {
			return new ArrayList<StudentEntity>();
		} else {
			PageHelper.startPage(page, pageNum);
			try {
				List<StudentEntity> students= mapper.findAll();
				return students;
			}finally {
				// 保证线程安全
				PageHelper.clearPage();
			}
		}
	}

}
